package com.mybatispluslambda.mybatis.metaobject;

import lombok.Data;
import org.apache.ibatis.reflection.DefaultReflectorFactory;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;

import java.util.ArrayList;
import java.util.List;

@Data
public class Animal {
    private Animal parent;
    private String name;


    public static void main(String[] args) {
        // Test Java Bean
//        Animal animal = new Animal();
//        MetaObject metaObject = MetaObject.forObject(animal, new DefaultObjectFactory(), new DefaultObjectWrapperFactory(), new DefaultReflectorFactory());
//        metaObject.setValue("name", "bean");
//        System.out.println(animal.getName());

        Animal animal = new Animal();
        animal.setName("collection");
        List<Animal> list = new ArrayList<>();
        MetaObject metaObject = MetaObject.forObject(list, new DefaultObjectFactory(), new DefaultObjectWrapperFactory(), new DefaultReflectorFactory());
        metaObject.add(animal);
        metaObject.setValue("", "ss");
        System.out.println(list.get(0).getName());

    }


}